package com.ysx.behaviour.listener;

import com.alibaba.fastjson.JSON;
import com.ysx.behaviour.dto.FollowBehaviorDto;
import com.ysx.behaviour.service.ApFollowBehaviorService;
import com.ysx.common.constants.BusinessConstants;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class FollowBehaviorListener {

    @Autowired
    private ApFollowBehaviorService apFollowBehaviorService;

    //监听消息
    @KafkaListener(topics = BusinessConstants.MqConstants.FOLLOW_BEHAVIOR_TOPIC)
    public void receiverMessage(ConsumerRecord<?,?> record){
        if(record!=null){
            FollowBehaviorDto dto = JSON.parseObject(record.value().toString(), FollowBehaviorDto.class);
            //保存关注行为数据
            apFollowBehaviorService.saveFollowBehavior(dto);
        }
    }
}